//
//  LoginAccountInfo.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2025/5/22.
//  Copyright © 2025 Mr.Wang. All rights reserved.
//

#import "LoginAccountInfo.h"
#import "EDSUtility.h"

@implementation LoginAccountInfo

+ (NSArray *)getAccounts:(NSString *)key {
    id tmp = [EDSUtility objectForKey:key];
    if (tmp == nil) {
        return @[];
    }
    return (NSArray *)tmp;
}

+ (void)saveAccounts:(NSArray *)list key:(NSString *)key {
    [EDSUtility setObject:list forKey:key];
}

/// 保存账号
/// - Parameter account: account description
+ (void)saveAccount:(NSString *)account completion:(nonnull void (^)(void))completion {
    NSArray *list = [self getAccounts:@"kSaveDeleteAccountInfos"];
    NSMutableArray *addList = [[NSMutableArray alloc] initWithArray:list];
    [addList addObject:account];
    NSLog(@"addlist=%@", addList);
    [self saveAccounts:addList key:@"kSaveDeleteAccountInfos"];
    if (completion) {
        completion();
    }
}

/// 判断账号是否存在
/// - Parameter account: account description
+ (BOOL)isAccountExists:(NSString *)account {
    NSArray *list = [self getAccounts:@"kSaveDeleteAccountInfos"];
    if (!list || list.count <= 0) {
        return NO;
    }
    
    BOOL res = NO;
    for (NSString *str in list) {
        if ([str isEqualToString:account]) {
            res = YES;
            break;
        }
    }
    return res;
}


@end
